/*
 * (C) 2012	Sheng Yi
 * Create a session and obtain its property
 */
#include "apue.h"

int main()
{
	pid_t pid;
	if ((pid = fork()) < 0)
		err_quit("fork error");
	else if (pid == 0) /* child */
	{
		printf("before setsid call: ");
		printf("pid = %d, pgrp = %d, sid = %d\n", getpid(), getpgrp(), getsid(getpid()));
//		sleep(1);
		/* Create a session */
		if ((pid = setsid()) == -1)
			err_quit("setsid error");
		printf("after setsid call: ");
		printf("pid = %d, pgrp = %d, sid = %d\n", getpid(), getpgrp(), getsid(getpid()));

		/* use terminal */

		exit(0);
	}
	else
	{
		//sleep(5);	/* sleep so child had enough time to create session */
		exit(0);
	}
}
